<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class posts extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->helper('url');
        echo( $this->load->view('menu', '', true) ); // Necessary for now because, for some reason, if you just do $this->load->view('menu'), it is printed to the HTML after all the below echo statements.
        $this->load->database();

        $query = $this->db->get_where('wp_posts', array('post_status' => 'publish'));
        foreach ($query->result() as $row)
        {
            echo $row->ID . ': ';
            echo anchor('posts/single/'.$row->ID, $row->post_title, 'title="'.$row->post_date.'"').'<br/>';
        }
    }
    function single()
    {
        $this->load->helper('url');
        echo( $this->load->view('menu', '', true) ); // Necessary for now because, for some reason, if you just do $this->load->view('menu'), it is printed to the HTML after all the below echo statements.
        if($this->uri->segment(3) === FALSE)
        {
            die('Need a post ID in URI segment 3.');
        }
        $this->load->database();
        $query = $this->db->get_where('wp_posts', array('post_status' => 'publish', 'ID' => $this->uri->segment(3)));
        

        foreach ($query->result() as $row)
        {
            echo '<h1>'.$row->post_title.'</h1>';

            echo str_replace("<p></p>", "", str_replace("\n" , "</p><p>", $row->post_content)).'<br/>';
        }
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */